package 剑指offer_leetcode;

import java.util.HashMap;

/**
 * JZ48最长不含重复字符的子字符串
 */
public class 剑指Offer48_最长不含重复字符的子字符串 {
    public int lengthOfLongestSubstring(String s) {
        HashMap<Character,Integer> map = new HashMap<>();
        int res = 0;
        for(int left =0 , right =0 ; right<s.length(); right++){
            if(map.containsKey(s.charAt(right)))
                map.put(s.charAt(right),map.get(s.charAt(right))+1);
            else
                map.put(s.charAt(right),1);
            while(map.get(s.charAt(right))!=1)
                map.put(s.charAt(left),map.get(s.charAt(left++))-1);
            res = Math.max(res,right-left+1);
        }
        return res;
    }
}